<?php

namespace RedMVC\Drawing\Color;
use RedMVC;

/**
 * Hsb class
 * 
 * Also called HSV  
 *
 * @category    RedMVC
 * @package     Drawing 
 * @subpackage  Color 
 * @author      Jan Fischer, bitWorking <info@bitworking.de>
 */
class Hsb{

    public $h;
    public $s;
    public $b;
    
    public function __construct($h, $s, $b){
        $this->h = min(max($h, 0), 360);
        $this->s = min(max($s, 0), 100);
        $this->b = min(max($b, 0), 100);
    }
    
    public static function normalize(Hsb $hsb){
        $self = new self($hsb->h, $hsb->s / 100, $hsb->b / 100);
        return $self;
    }
    
    public function __toString(){
        return 'hsb('.$this->h.','.$this->s.','.$this->b.')';
    }
    
    public function toHex(){
        return RedMVC\Drawing\Color::hsb2hex($this);
    }

}